﻿using SysManage.BLL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using ZHDJ.WebPage;

namespace SysManage.Module.Article
{
    /// <summary>
    /// uploadfile 的摘要说明
    /// </summary>
    public class uploadfile : PageBase, IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //接收上传后的文件
            HttpPostedFile file = context.Request.Files["Filedata"];
            //判断上传的文件是否为空
            if (file != null)
            {
                //保存文件
                var rs = UpFileBusiness.Upload(file, "admin");
                ResponseModel rm = new ResponseModel();
                rm.Id = rs.FileID + ",";
                rm.state = 0;
                rm.Msg = "OK";
                rm.FileTitle = rs.FileTitle + ",";
                rm.Path = rs.FileUrl + ",";
                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(rm));//即传给前台的data
            }
            else
            {
                context.Response.Write("0"); //即传给前台的data
            }
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class ResponseModel
    {
        public string Id { get; set; }

        public int state { get; set; }

        public string Msg { get; set; }

        public string Path { get; set; }

        public string FileTitle { get; set; }
    }

}